
import java.util.List;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* @author :${author}
* @description: ${desc}数据库操作类
* @create date: ${createDate}
*/

@Repository
public class ${entityName}Dao {

    @Autowired
    ${entityName}Mapper ${entityNameLower}Mapper;

    /**
    * 保存${desc}
    * @param ${entityNameLower}
    * @return
    */
    public int add(${entityName} ${entityNameLower}) {
        return ${entityNameLower}Mapper.insert(${entityNameLower});
    }
    
    
    <#if primaryKey!='noPrimaryKey'>
    /**
    * 根据ID更新${desc}
    * @param ${entityNameLower}
    * @return
    */
    public int update(${entityName} ${entityNameLower}) {
        return ${entityNameLower}Mapper.updateById(${entityNameLower});
    }
    
    /**
    * 删除${desc}
    * @param ${primaryKey}
    * @return
    */
    public int del(${javaKeyType} ${primaryKey}) {
        return ${entityNameLower}Mapper.deleteById(${primaryKey});
    }

    /**
    * 根据查询${desc}
    * @param ${primaryKey}
    * @return
    */
    public ${entityName} get(${javaKeyType} ${primaryKey}) {
        return ${entityNameLower}Mapper.selectById(${primaryKey});
    }
    </#if>

    /**
    * 查询${desc}
    * @param ${entityNameLower}
    * @return
    */
    public List<${entityName}> findList(${entityName} ${entityNameLower}) {
        QueryWrapper<${entityName}> queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(${entityNameLower});
        return ${entityNameLower}Mapper.selectList(queryWrapper);
    }

    /**
    * 查询${desc}(分页)
    * @param ${entityNameLower}
    * @return
    */
    public void findPageList(Page<${entityName}> page,${entityName} ${entityNameLower}) {
        QueryWrapper<${entityName}> queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(${entityNameLower});
        // page.addOrder(OrderItem.desc("id"))
        ${entityNameLower}Mapper.selectPage(page, queryWrapper);
    }
}
